package com.bgds.sys.api.feign;

import com.bgds.sys.common.utils.DateUtils;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * @author Smiling
 * @description: TODO
 * @date 2021/4/28  20:11
 */
public class BaoXinClient {
    private static OkHttpClient client;

    /**
     * 单例模式  获取类实例
     *
     * @return client
     */
    private static OkHttpClient getInstance() {
        if (client == null) {
            synchronized (OkHttpClient.class) {
                if (client == null) {
                    client = new OkHttpClient.Builder()
                            .connectTimeout(5, TimeUnit.SECONDS)
                            .readTimeout(7, TimeUnit.SECONDS)
                            .build();
                }
            }
        }
        return client;
    }

    public static String doPost() throws Exception {
        FormBody.Builder builder = new FormBody.Builder();
//        builder.add("STARTTIME", "2021-02-21 00:00:00");
//        builder.add("ENDTIME", "2021-11-21 23:59:00");
        builder.add("STARTTIME", DateUtils.getBeforeByHourTime(1));
        builder.add("ENDTIME", DateUtils.convertDate2String("yyyy-MM-dd HH:mm:ss", new Date()));
        FormBody formBody = builder.build();
        Request request = new Request.Builder()
                .url("http://172.16.202.36:8080/ZNYY/GETFAULT").post(formBody).build();
        Response response = getInstance().newCall(request).execute();
        return response.body().string();
    }
}